package com.itheima.homework;

import java.text.ParseException;
import java.time.Duration;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.time.format.DateTimeFormatter;
import java.util.Scanner;

public class demo01 {
    public static void main(String[] args) throws ParseException {
        // 用户输入字符串解析格式
        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
        Scanner sc = new Scanner(System.in);
        System.out.println("请输入生日(格式：2024-11-11)：");
        String str = sc.next();
        // 将用户输入的生日转换成日期类型
        LocalDate birth = LocalDate.parse(str, formatter);
        // 获取当前日期时间
        LocalDateTime now = LocalDateTime.now();
        // 用于将输入的生日和下面的时间合并成LocalDateTime类型，从而使用Duration对象计算天数
        LocalTime lt = LocalTime.of(0, 0, 0, 0);
        LocalDateTime birth_ldt = LocalDateTime.of(birth, lt);
        Duration duration = Duration.between(birth_ldt, now);
        long days = duration.toDays();
        System.out.println(STR."您已经活了\{days}天了");
    }
}
